package com.lsfb.signln.Utils;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;

import com.lsfb.signln.R;

/**
 * Created by nonsense on 2017/8/3.
 */

public abstract class DialogBuilder {

    private Dialog dialog;
    private Activity mActivity;

    public DialogBuilder(Activity activity, int layout) {
        mActivity = activity;
        LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        dialog = new Dialog(mActivity, R.style.Dialog);
        View view = inflater.inflate(layout, null);
        view.setMinimumWidth((int) (mActivity.getWindowManager().getDefaultDisplay().getWidth() * 0.85));
        dialog.addContentView(view, new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        dialog.setContentView(view);

        ViewListener(view, this);

    }

    abstract public void ViewListener(View contentview, DialogBuilder dialogBuilder);


    public void showDialog() {
        if (dialog != null && !dialog.isShowing()) {
            dialog.show();
        }
    }

    public void hideDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    public void SetDialogTouchDismiss(boolean cantouchoutsidedismiss) {
        if (dialog != null) {
            dialog.setCanceledOnTouchOutside(cantouchoutsidedismiss);
        }
    }
}
